from fastapi import APIRouter

users_router = APIRouter()


@users_router.get("/reg/")
async def reg():
    return ["Rick", "Morty"]


from urllib.parse import quote



@users_router.get("/geturl/")
async def geturl(types):
    my_class = property.create_class(types)
    url = my_class.geturl()
    return {"url": url}


import requests


@users_router.get("/callback/")
async def callback():
    authCode = requests.query_params.get('code')
    types = requests.query_params.get('types')
    my_class = property.create_class(types)
    userdict = my_class.callback(authCode)

    # 查询三方登录表中是否存在该用户
    # 如果存在获取用户信息，
    # 如果不存在写入用户表，三方登录表
    # 调用 jwt生成token retoken

    # 初始化参数列表
    return {"msg": "success", 'userid': 1, 'token': '', 'retoken': ''}


from tools.myredis import r


@users_router.get("/callback/")
async def imagecode(img):
    r.lpush('imagelist', img)
    return {}




